package com.example.thealarm;

import static com.example.thealarm.MainActivity.Date;
import static com.example.thealarm.MainActivity.Name;
import static com.example.thealarm.MainActivity.Repeat_NO;
import static com.example.thealarm.MainActivity.Repeat_TYPE;
import static com.example.thealarm.MainActivity.Time;
import static com.example.thealarm.MainActivity.Type;

import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.transition.Hold;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    Context mCon;
    View view;
    public MyAdapter(Context context) {
        mCon = context;
    }

    @NonNull
    @Override

    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(mCon).inflate(R.layout.theitempage,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.Title.setText(Name.get(position));
        holder.TheTimeAndDate.setText("闹钟设定为: "+Date.get(position)+" "+Time.get(position));
        holder.TheRepeatAndType.setText("间隔和类型:"+Repeat_NO.get(position)+" "+Repeat_TYPE.get(position));
        holder.linear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mCon,TheSetPage.class);
                Uri currentVehicleUri= ContentUris.withAppendedId(TheDataBase.DataBaseEntry.CONTENT_URI,position);
                intent.setData(currentVehicleUri);
                intent.putExtra("position",position);
                mCon.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {
        return Time.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView Title,TheTimeAndDate,TheRepeatAndType;
        LinearLayout linear ;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            Title=itemView.findViewById(R.id.TheTitle);
            TheTimeAndDate=itemView.findViewById(R.id.TheTimeAndDate);
            TheRepeatAndType = itemView.findViewById(R.id.TheRepeatAndType);
            linear=itemView.findViewById(R.id.linear);
        }
    }
}
